package org.brakepedal.server.support.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.Objects;

/**
 * Date: 2023/2/4 19:53
*/
@Slf4j
public class RequestURLLogger implements HandlerInterceptor {
    @Override
    public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
        log.info("Host: {}  URI: {}{}  Method: {} ",
                request.getRemoteHost(),
                request.getRequestURI(),
                Objects.isNull(request.getQueryString()) ?"": "?"+request.getQueryString(),
                request.getMethod());
        return true;
    }
}
